home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / samples / shootemup / main.bb next >
Encoding:
Text File  |  2002-04-10  |  4.9 KB  |  253 lines

  1. AppTitle "ENGINE v0.3 (PRESS MOUSE BUTTON TO EXIT POST-DEBUG INFO)"
  2.  
  3. Include "includes/math.h"
  4. Include "includes/cloudfx.h"
  5. Include "includes/types.h"
  6. Include "includes/script.h"
  7. Include "includes/loader.h"
  8.  
  9. Include "includes/plyfire.h"
  10. Include "includes/points.h"
  11.  
  12. Include "levels/level1.bb"
  13.  
  14. Graphics 640,480
  15. SetBuffer BackBuffer()
  16.  
  17. Dim mapxy_data(32000)
  18.  
  19. ;player settings
  20. Global ply_speed=4
  21. Global ply_y=390
  22. Global ply_x=288
  23. Global ply_roll
  24. Global ply_rollspeed=2
  25. Global ply_points=0
  26. Global ply_lives=3
  27.  
  28. ;envorment settings
  29. Global landspeed=1
  30. Global scrollmapy=0
  31. Global linestepper=0
  32. Global offsetmapx=-192/2
  33. Global mapend
  34.  
  35. ;path
  36. Global tstoffset
  37. Global axp
  38. Global ayp
  39.  
  40. ;temporary alien veriables
  41. Global layer0_aliens=14
  42. Global layer0_aliens_speed=2
  43. Global layer0_aliens_counter
  44. Global layer0_aliens_space=128
  45. Global fooboo
  46.  
  47. ;loaded graphical data
  48. Global tileset=LoadAnimImage("sprites/maptiles/sand.bmp",64,64,0,44)
  49. Global plyset=LoadAnimImage("sprites/player/plyshp01a.bmp",64,64,0,15)
  50. Global cloud_fximg=LoadAnimImage("sprites/fx/clouds.bmp",132,133,0,5)
  51. Global plyfire=LoadAnimImage("sprites/player/std_fire.bmp",16,16,0,7)
  52. Global hudimg=LoadImage("sprites/menu/hud.bmp")
  53. Global fontnumbers=LoadAnimImage("sprites/fonts/numbers_ingame.bmp",8,7,0,10)
  54.  
  55. ;buffers
  56. Global hudbufferimg=CreateImage(ImageWidth(hudimg),ImageHeight(hudimg)) 
  57.  
  58. ;masks
  59. MaskImage hudbufferimg,255,0,255
  60. MaskImage hudimg,255,0,255 ; kludge
  61.  
  62.  
  63.  
  64. temp()
  65. loadenermy()
  66. loadpath("path/sqr.arp")
  67. init_clouds()
  68. init_aliens()
  69.  
  70. Global al_image=findnme("AverBio") ; init the first alien (testing)
  71.  
  72. While Not KeyDown(1)
  73.  
  74.     scrollmap()
  75.     cloudfx_bottomlayer()    
  76.     plyctrl()
  77.     alnctrl()    
  78.     DrawImage plyset,ply_x,ply_y,6+ply_roll
  79.     update_bullets()
  80.     offsetmapx=-ply_x/4-96/2
  81.     cloudfx_toplayer()
  82.     For cnx=0 To ply_bullets
  83.         For alcn=0 To layer0_aliens
  84.             If mneinfo_layer0(alcn)\dead=0
  85.                 al_hit=ImagesOverlap(al_image,mneinfo_layer0(alcn)\x,mneinfo_layer0(alcn)\y,plyfire,fwd_plybullet(cnx,1),fwd_plybullet(cnx,2))
  86.                 If al_hit=1 Then mneinfo_layer0(alcn)\dead=1 : addpoints(100)
  87.             EndIf
  88.         Next
  89.     Next
  90.  
  91.     DrawImage hudimg,0,456
  92.     
  93.     ;If MouseHit(1)
  94.  
  95.         drawpoints(76,465,ply_points)
  96.         drawpoints(273,465,ply_lives)
  97.     ;EndIf
  98.  
  99.     Flip
  100.  
  101.     ; SNAPSHOT PLEASE
  102.     If KeyDown(88)
  103.         SaveBuffer(FrontBuffer(),"snapshot.bmp")
  104.     EndIf
  105.  
  106.     Cls : VWait
  107. Wend
  108.  
  109. End
  110.  
  111. ;
  112. ; Alien Control
  113. ;
  114. Function alnctrl()
  115.  
  116. For alcn=0 To layer0_aliens
  117.     If mneinfo_layer0(alcn)\path_lcounter=>pathinfo\steps-4
  118.         mneinfo_layer0(alcn)\path_lcounter=0
  119.     EndIf
  120.     getpath(mneinfo_layer0(alcn)\path_lcounter)
  121.  
  122.     mneinfo_layer0(alcn)\x=axp
  123.     mneinfo_layer0(alcn)\y=ayp
  124.     mneinfo_layer0(alcn)\path_lcounter=mneinfo_layer0(alcn)\path_lcounter+4
  125.     If mneinfo_layer0(alcn)\dead=0
  126.         DrawImage al_image,mneinfo_layer0(alcn)\x,mneinfo_layer0(alcn)\y,fooboo
  127.     EndIf
  128. ;    Text 0,0,"("+axp+")("+ayp+")"+(fooboo Mod layer0_aliens_space)
  129. Next 
  130.     fooboo=fooboo+1 
  131.     If fooboo>18 Then fooboo=0
  132.  
  133. End Function
  134.  
  135. Function init_aliens()
  136.  
  137.     For alcn=0 To layer0_aliens
  138.         mneinfo_layer0(alcn)\path_lcounter=mneinfo_layer0(alcn)\path_lcounter+(layer0_aliens_space*alcn)
  139.     Next
  140.  
  141. End Function 
  142. ;
  143. ; Collisions
  144. ;
  145.  
  146. ;
  147. ; Find An Alien
  148. ;
  149. Function findnme(askname$)
  150.  
  151.     While askname$<>nmeinfo\name$
  152.         nmeinfo=After nmeinfo
  153.         Print nmeinfo\name$
  154.     Wend
  155.  
  156.     Return nmeinfo\image
  157. End Function
  158.  
  159. ;
  160. ; Get Path X,Y
  161. ;
  162. Function getpath(offset)
  163.     ;Print offset
  164.     axp=PeekShort(pathinfo\memptr,  pathinfo\dataoffset+offset)
  165.      ayp=PeekShort(pathinfo\memptr,2+pathinfo\dataoffset+offset)
  166.     ;Print axp+" "+pathinfo\dataoffset+" "+offset+" "+pathinfo\steps
  167. End Function
  168.  
  169. ;
  170. ; Player Control 
  171. ;
  172. Function plyctrl()
  173.  
  174.     not_roll=False
  175.     ; left
  176.     If KeyDown(203)
  177.         ply_x=ply_x-ply_speed
  178.         ply_roll=ply_roll-ply_rollspeed
  179.         ply_x=Min(ply_x,2)
  180.         not_roll=True
  181.     EndIf
  182.     ; right
  183.     If KeyDown(205)
  184.         ply_x=ply_x+ply_speed
  185.         ply_roll=ply_roll+ply_rollspeed
  186.         ply_x=Max(ply_x,574)
  187.         not_roll=True
  188.     EndIf
  189.     ; up
  190.     If KeyDown(200)
  191.         ply_y=ply_y-ply_speed
  192.         ply_y=Min(ply_y,0)
  193.     EndIf
  194.     ; down
  195.     If KeyDown(208)
  196.         ply_y=ply_y+ply_speed
  197.         ply_y=Max(ply_y,400)
  198.     EndIf
  199.     ; fire
  200.     If KeyHit(157)
  201.         shoot_bullets()
  202.     EndIf
  203.         
  204.     ; roll back
  205.     If not_roll=False
  206.         If ply_roll>0 Then ply_roll=ply_roll-ply_rollspeed
  207.         If ply_roll<0 Then ply_roll=ply_roll+ply_rollspeed
  208.     EndIf
  209.  
  210.     ply_roll=Min(ply_roll,-5)
  211.     ply_roll=Max(ply_roll,5)        
  212.  
  213. End Function
  214.  
  215. ;
  216. ; Scroll Map
  217. ;
  218. Function scrollmap()
  219.  
  220.     x=832 : y=430
  221.  
  222.      mapstart=linestepper+mapend-125
  223.     
  224.     For cntiles=mapend+linestepper To mapstart Step -1
  225.         tile=mapxy_data(cntiles)
  226.         
  227.         DrawImage tileset,x+offsetmapx,y+scrollmapy,tile
  228.  
  229.         x=x-64
  230.         If x<0 
  231.             x=832 : y=y-64
  232.         EndIf
  233.     Next
  234.     
  235.     scrollmapy=scrollmapy+landspeed
  236.     If scrollmapy>64
  237.         scrollmapy=0
  238.         linestepper=linestepper-14
  239.     EndIf
  240.     
  241.     
  242. End Function
  243.  
  244.  
  245. Function temp()
  246.  
  247.     Repeat
  248.         Read x : If x=-1 Then Return         
  249.         mapxy_data(cn)=x-1
  250.         cn=cn+1 : mapend=cn
  251.     Until x=-1
  252.  
  253. End Function